package com.slashmobility.finappsparty.helper;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.text.format.DateFormat;

public class DateHelper {
	
	/**Dado year YYYY month MM y mDay DD, formatea la fecha en el formato especificado*/
	public static String getFormatedDate(int mYear, int mMonth, int mDay)
	{
		try
		{
			return DateFormat.format("dd/MM/yyyy", new Date(mYear-1900, mMonth, mDay)).toString();
		}catch(Exception e)
		{			
			return null;
		}
	}
	
	/**Dada una fecha 03-ene-2011 0:00:00 (dd-MMM-yyyy h:mm:ss) devuelve dd/mm/yyyy */
	public static String getFormatedDateFrom(String date)
	{
		try
		{
			Format formatter = new SimpleDateFormat("dd-MMM-yyyy h:mm:ss");
		    Date newDate = (Date) formatter.parseObject(date);
		    return getFormatedDate(newDate.getYear()+1900, newDate.getMonth(), newDate.getDay());
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
 	}
	
	/**Dada una fecha 2011/04/20 09:02:00, devuelve un tipo Date */
	
	public static Date getDateFromFormated(String date)
	{
		try
		{
			Format formatter = new SimpleDateFormat("yyyy/MM/dd kk:mm:ss");
		    Date newDate = (Date) formatter.parseObject(date);
		    
		    return newDate;
		}catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
 	}
	
	/** Dado un "XX:XX:XX" devuelve un "XX:XX" */
	public static String roundTime(String timeString)
	{
		try
		{
			return timeString.subSequence(0, 8).toString();
		}
		catch(Exception e)
		{
			return "N/A";
		}
	}
}
